var layer = layui.layer //弹层
    ,form = layui.form,$ = layui.jquery,laydate = layui.laydate;

var code=getQueryVariable("code");
var ym=getQueryVariable("ym");
var codes=code.split(",");
var obj="";
for(var i=0;i<codes.length;i++){
    obj=obj+"&"+codes[i];
}
obj=obj.replaceAll(":","=");
//ym=ym+"##"+obj;

var reporturl=getReportUrl();
//reporturl="http://localhost:6001/quiee/reportJsp/showReport.jsp?raq=/";
var url="";
    url=reporturl+ym+".raq"+obj;
$("#reporturl")[0].src=url;
$("#searchs").click(function(){
    url=reporturl+ym+".raq";
    var code=$("#code")[0].value;
    var type=$("#type")[0].value;
    var usercode=$("#salesman")[0].value
    var name=$("#name")[0].value
    var starttime=$("#startshdate")[0].value;
    var endtime=$("#endshdate")[0].value;
    if(usercode==""){
        usercode=user.code;
    }else{
         usercode= getUsercodeByname(usercode);
    }
    if(name !=""){
        name=getcodeByname(name);
    }
    if(type==""){
        for(var i=0;i<fls.length;i++){
                type=type+","+fls[i].code;
        }
    }
    if(starttime==""){
        starttime="1971-01-01";
    }
    if(endtime==""){
        endtime="2100-01-01";
    }

url=url+"&code="+code+"&type="+type+"&updater="+usercode+"&starttime="+starttime+"&endtime="+endtime;

    $("#reporturl")[0].src=url;
});

var fls=getdictionary(6,27);//客户类型
//下拉列表重新赋值
setselecttype(fls,"type");
//查询条件中类型

function setselecttype(dt,key) {
    var options="";
    for(var i=0;i<dt.length;i++){
        options+="<option value='"+dt[i].code+"'>"+dt[i].name+"</option>";
    }
    $("#"+key+"").append(options);

}

//获取字典
function getdictionary(dl,xl) {
    var obj=[];
    $.ajax({
        type : 'POST',
        //  url : 'resource/getTree',
        data: {"type":dl,"lx":xl},
        url:'dictionary2/getValues',
        dataType:"json",
        async:false,
        success : function (da) {
            if(da.status==200 ){
                obj=da.data;
            }
        },
        error: function(data) {
        }
    });
    return obj;
}
//获取报表url前缀
function  getReportUrl() {
    var url=getdictionary(6,54);
    return url[1].name;
}
lay('.starttime').each(function(){
    laydate.render({
        elem: this,
        max: 0,//最大值为当前日期
        eventElem: '#starttime',//日期输入框的图标，给图标也绑定点击事件
        trigger: 'click'
        //,value: new Date() //默认值30天前
    });
});
function getcodeByname(name) {
    var names="";
    //根据名称获取客户编码
    $.ajax({
        type : 'get',
        //  url : 'resource/getTree',
        data: {"name":name},
        url:'customer/getcodeByname',
        dataType:"json",
        // contentType: 'application/json',
        async:false,
        success : function (da) {
            if(da.status==200 ){
                var data=da.data;
                for(var i=0;i<data.length;i++){
                    names=names+","+data[i];
                }
            }
        },
        error: function(data) {
        }
    });
    return names;
}
function getUsercodeByname(name) {
    var names="";
    //根据名称获取客户编码
    $.ajax({
        type : 'get',
        //  url : 'resource/getTree',
        data: {"name":name},
        url:'customer/getUsercodeByname',
        dataType:"json",
        async:false,
        success : function (da) {
            if(da.status==200 ){
                var data=da.data;
               for(var i=0;i<data.length;i++){
                       names=names+","+data[i];
               }
            }
        },
        error: function(data) {
        }
    });
    return names;
}